<template>
	<div>
		<!--引用表格-->
		<BasicTable @register="registerTable" :rowSelection="rowSelection">
			<!--插槽:table标题-->
			<template #tableTitle>
				<a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增行程</a-button>

				<!-- <a-button type="primary" @click="bindCarUpdate" v-if="selectedRowKeys.length > 0"
					preIcon="ant-design:car-outlined">车辆绑定修改</a-button> -->
				<a-button type="primary" @click="combinedTravel"
					v-if="selectedRowKeys.length > 0 && rowSelection.selectedRows[0].statusCarpool==0"
					preIcon="ant-design:compress-outlined">合并行程</a-button>
				<a-button type="primary" @click="cancelJourney"
					v-if="selectedRowKeys.length > 0 && rowSelection.selectedRows[0].statusCarpool!=-1"
					preIcon="ant-design:issues-close-outlined">取消行程</a-button>
				<a-button type="primary" @click="groupSuccessfullyConfirm"
					v-if="selectedRowKeys.length > 0 && rowSelection.selectedRows[0].statusCarpool!=-1"
					preIcon="ant-design:appstore-outlined">拼团成功</a-button>
				<a-button type="primary" @click="sendNotification"
					v-if="selectedRowKeys.length > 0 && rowSelection.selectedRows[0].statusCarpool!=-1"
					preIcon="ant-design:info-circle-outlined">发送通知</a-button>
			<!-- 	<a-button type="primary" @click="hotelArrangement"
					v-if="selectedRowKeys.length > 0 && rowSelection.selectedRows[0].statusCarpool!=-1"
					preIcon="ant-design:info-circle-outlined">酒店统一安排</a-button> -->
				<a-button type="primary" @click="auditSchedule"
					v-if="selectedRowKeys.length > 0 && rowSelection.selectedRows[0].userInitiatedAuditStatus==0"
					preIcon="ant-design:info-circle-outlined">行程审核</a-button>
				<!-- 通知里面有群二维码，签合同通知，绑定领队 -->
				<!-- <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
				<j-upload-button type="primary" preIcon="ant-design:import-outlined"
					@click="onImportXls">导入</j-upload-button> -->
				<a-dropdown v-if="selectedRowKeys.length > 0">
					<template #overlay>
						<a-menu>
							<a-menu-item key="1" @click="batchHandleDelete">
								<Icon icon="ant-design:delete-outlined"></Icon>
								删除
							</a-menu-item>
						</a-menu>
					</template>
					<a-button>批量操作
						<Icon icon="mdi:chevron-down"></Icon>
					</a-button>
				</a-dropdown>
			</template>
			<!--操作栏-->
			<template #action="{ record }">
				<TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
			</template>
			<!--字段回显插槽-->
			<template v-slot:bodyCell="{ column, record, index, text }">
			</template>
		</BasicTable>
		<!--子表表格tab-->
		<a-tabs defaultActiveKey="1" style="margin-left:20px;">
			<a-tab-pane tab="行程按天连线" key="1">
				<CoupleActivityScenicSpotConnectionList />
			</a-tab-pane>
			<a-tab-pane tab="报名用户" key="2" forceRender>
				<CoupleActivityOrderList />
			</a-tab-pane>
			<a-tab-pane tab="车辆+领队+上车地点" key="3" forceRender>
				<CoupleActivityCarpoolBusAndLeaderList />
			</a-tab-pane>
			<a-tab-pane tab="消息接收详情" key="4" forceRender>
				<CoupleInformDetailList />
			</a-tab-pane>
			<!-- 		<a-tab-pane tab="用户发起团的审核" key="5" forceRender>
				<CoupleActivityCarpoolBusUserAuditList />
			</a-tab-pane> -->
			<a-tab-pane tab="行程评论列表" key="6" forceRender>
				<CoupleCommentList />
			</a-tab-pane>
			<a-tab-pane tab="梯度价格" key="7" forceRender>
				<CoupleActivityCarpoolBusGradientPriceList />
			</a-tab-pane>
			<a-tab-pane tab="用户发起团的审核记录" key="8" forceRender>
				<CoupleActivityCarpoolBusUserAuditList />
			</a-tab-pane>
		</a-tabs>
		<!-- 表单区域 -->
		<CoupleActivityCarpoolBusModal @register="registerModal" @success="handleSuccess">
		</CoupleActivityCarpoolBusModal>
		<CancelJourneyModule @register="registerCancelJourneyModal" @success="handleSuccess">
		</CancelJourneyModule>
		<CombinedTravelModule @register="registerCombinedJourneyModal" @success="handleSuccess">
		</CombinedTravelModule>
		<SendNotificationModule @register="registerSendNotificationModal" @success="handleSuccess">
		</SendNotificationModule>
		<BindCarUpdateModule @register="registerBindCarUpdateModal" @success="handleSuccess">
		</BindCarUpdateModule>
		<CoupleActivityCarpoolBusUserAuditModal @register="registerAuditScheduleModal" @success="handleSuccess" />
		<HotelArrangementModule @register="registerHotelArrangementModal" @success="handleSuccess" />

	</div>
</template>

<script lang="ts" name="activity-coupleActivityCarpoolBus" setup>
	import { ref, computed, unref, provide } from 'vue';
	import { BasicTable, useTable, TableAction } from '/@/components/Table';
	import { useListPage } from '/@/hooks/system/useListPage'
	import { useModal } from '/@/components/Modal';
	import CoupleActivityCarpoolBusUserAuditList from './CoupleActivityCarpoolBusUserAuditList.vue'
	import CoupleActivityCarpoolBusModal from './components/CoupleActivityCarpoolBusModal.vue'
	import CancelJourneyModule from './module/order/CancelJourneyModule.vue'
	import HotelArrangementModule from './module/order/HotelArrangementModule.vue'
	import CombinedTravelModule from './module/order/CombinedTravelModule.vue'
	import CoupleActivityCarpoolBusUserAuditModal from './module/order/AuditJourneyModule.vue'
	import BindCarUpdateModule from './module/order/BindCarUpdateModule.vue'
	import SendNotificationModule from './module/order/SendNotificationModule.vue'
	import { useUserStore } from '/@/store/modules/user';
	import CoupleActivityCarpoolBusAndLeaderList from './CoupleActivityCarpoolBusAndLeaderList.vue'
	import CoupleInformDetailList from './CoupleInformDetailList.vue'
	import CoupleCommentList from './CoupleCommentList.vue'
	import CoupleActivityCarpoolBusGradientPriceList from './CoupleActivityCarpoolBusGradientPriceList.vue'
	import CoupleActivityOrderList from './CoupleActivityOrderFubiaoList.vue'
	import CoupleActivityScenicSpotConnectionList from './CoupleActivityScenicSpotConnectionList.vue'
	import { columns, searchFormSchema } from './CoupleActivityCarpoolBus.data';
	import { list, groupSuccessfully, deleteOne, batchDelete, getImportUrl, getExportUrl, updateCarpoolBusStatusById, confirmCarpoolBus } from './CoupleActivityCarpoolBus.api';
	import { downloadFile } from '/@/utils/common/renderUtils';
	//注册model
	const [registerModal, { openModal }] = useModal();
	//合并行程
	const [registerCombinedJourneyModal, { openModal: openCombinedJourneyModal }] = useModal();
	//取消行程
	const [registerCancelJourneyModal, { openModal: openCancelJourneyModal }] = useModal();
	const [registerSendNotificationModal, { openModal: openSendNotificationModal }] = useModal();
	const [registerBindCarUpdateModal, { openModal: openBindCarUpdateModal }] = useModal();
	const [registerAuditScheduleModal, { openModal: openAuditScheduleeModal }] = useModal();
	const [registerHotelArrangementModal, { openModal: openHotelArrangementModal }] = useModal();


	//注册table数据
	const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
		tableProps: {
			title: '拼包车管理',
			api: list,
			columns,
			canResize: false,
			rowSelection: { type: 'radio' },
			formConfig: {
				schemas: searchFormSchema,
				fieldMapToNumber: [
				],
				fieldMapToTime: [
				],
			},
			actionColumn: {
				width: 120,
				fixed: 'right'
			},
			pagination: {
				current: 1,
				pageSize: 5,
				pageSizeOptions: ['5', '10', '20'],
			},
			beforeFetch(params) {
				params.carpoolCategory = 0
				return params
			},
			//接口请求后获取数据
			afterFetch: (data) => {
			},
		},
		exportConfig: {
			name: "拼包车管理",
			url: getExportUrl,
		},
		importConfig: {
			url: getImportUrl,
			success: handleSuccess
		},
	})
	const userStore = useUserStore();
	const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext

	const mainId = computed(() => (unref(selectedRowKeys).length > 0 ? unref(selectedRowKeys)[0] : ''));
	//下发 mainId,子组件接收
	provide('mainId', mainId);

	function auditSchedule() {
		openAuditScheduleeModal(true, {

		})
	}
	function hotelArrangement() {
		openHotelArrangementModal(true, {

		})
	}
	function combinedTravel() {
		openCombinedJourneyModal(true, {

		})
	}
	function bindCarUpdate() {
		openBindCarUpdateModal(true, {

		})
	}
	function cancelJourney() {
		openCancelJourneyModal(true, {

		})
	}
	async function groupSuccessfullyConfirm() {
		await groupSuccessfully({ id: rowSelection.selectedRows[0].id }, handleSuccess);

	}
	function sendNotification() {
		openSendNotificationModal(true, {

		})
	}


	/**
	 * 新增事件
	 */
	function handleAdd() {
		openModal(true, {
			isUpdate: false,
			showFooter: true,
		});
	}
	/**
	 * 编辑事件
	 */
	function handleEdit(record : Recordable) {
		openModal(true, {
			record,
			isUpdate: true,
			showFooter: true,
		});
	}
	/**
	 * 详情
	*/
	function handleDetail(record : Recordable) {
		openModal(true, {
			record,
			isUpdate: true,
			showFooter: false,
		});
	}
	/**
	 * 删除事件
	 */
	async function handleDelete(record) {
		await deleteOne({ id: record.id }, handleSuccess);
	}
	/**
	 * 批量删除事件
	 */
	async function batchHandleDelete() {
		await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
	}
	/**
	 * 成功回调
	 */
	function handleSuccess() {
		(selectedRowKeys.value = []) && reload();
	}
	/**
	   * 操作栏
	   */
	function getTableAction(record) {
		return [
			{
				label: '编辑',
				onClick: handleEdit.bind(null, record),
			}
			/* {
				label: '待确认',
				popConfirm: {
					title: '是否确认该行程发起成功？',
					confirm: confirmSuccess.bind(null, record),
				},
				ifShow: (_action) => {
					return record.statusCarpool == 1; // 根据业务控制是否显示: 非enable状态的不显示启用按钮
				}
			} */
		]
	}

	function confirmSuccess(record : Recordable) {
		console.log(record)
		//await updateCarpoolBusStatusById({ id: record.id }, handleSuccess);
	}


	/**
	 * 下拉操作栏
	 */
	function getDropDownAction(record) {
		return [

			{
				label: '详情',
				onClick: handleDetail.bind(null, record),
			}, {
				label: '删除',
				popConfirm: {
					title: '是否确认删除',
					confirm: handleDelete.bind(null, record),
					placement: 'topLeft',
				}
			}
		]
	}
</script>

<style scoped>


</style>